package com.example.mobile2021606134chhnewdemo.ContactModule;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.mobile2021606134chhnewdemo.NewsModule.NewContentActivity;
import com.example.mobile2021606134chhnewdemo.NewsModule.News;
import com.example.mobile2021606134chhnewdemo.NewsModule.NewsRViewAdapter;
import com.example.mobile2021606134chhnewdemo.R;

import java.util.List;

/**
 * @ClassName: ContactRViewAdapter$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 3/7/2021$
 * @Version: 1.0
 */
public class ContactRViewAdapter extends RecyclerView.Adapter<ContactRViewAdapter.ViewHolder>{
    List<ContactMain> list;
    private Context context;
    public ContactRViewAdapter(List<ContactMain> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_contact, null);
        ContactRViewAdapter.ViewHolder viewHolder = new ContactRViewAdapter.ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ContactMain main = list.get(position);
        String name = main.getContactName();
        int pic = main.getPic();
        holder.tvContent.setText(name);
        Glide.with(context).load(pic).into(holder.imgContact);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (name){
                    case "图灵Robot":
                        Intent intent = new Intent(context, TuLinRobotActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
                        context.startActivity(intent);
                        break;
                    case "智能问答":
                        Intent intent1 = new Intent(context, SpeedRobotActivity.class);
                        intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
                        context.startActivity(intent1);
                    default:
                        break;
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvContent;
        ImageView imgContact;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            this.tvContent = itemView.findViewById(R.id.tvContent);
            this.imgContact = itemView.findViewById(R.id.imgContact);
        }
    }
}
